package test;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class HibernateUserDAOImpl extends HibernateDaoSupport implements IUserDao{

//	private HibernateTemplate template;
	//��������һ������setSessionFactory
//	public void setSessionFactory(SessionFactory sessionfactory){
//		this.template = new HibernateTemplate(sessionfactory);
//	}
	
	public void del(int id) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().delete(findId(id));
	}

	public List<User> findAll() {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from User");
		
	}

	public int findCount() {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().find("from User").size();
	}

	public User findId(int id) {
		// TODO Auto-generated method stub
		return (User)getHibernateTemplate().get(User.class, id);
		
	}

	public void save(User u) {
		// TODO Auto-generated method stub
    this.getHibernateTemplate().save(u);
	}

}
